package com.edu.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.entity.CommentDTO;
import com.edu.entity.CommonResult;
import com.edu.entity.Page;
import com.edu.entity.UserComents;
import com.edu.service.UserComentsService;
import com.edu.service.impl.UserComentsServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
@WebServlet("/selectAllUserComents")
public class findAllUserComentsServlet extends HttpServlet{
	UserComentsService ucs = new UserComentsServiceImpl();
	CommonResult cr = new CommonResult();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		ObjectMapper om = new ObjectMapper();
		List<CommentDTO> listUsc = null;
		int rowNum;
		String target_user_id_String = request.getParameter("target_user_id");//商家id
		String login_user_id = request.getParameter("current_user_id");
//		System.out.println(target_user_id_String+"111");
		try {
			int target_user_id = Integer.parseInt(target_user_id_String);
//			System.out.println(target_user_id+"商家id");
			int userId = Integer.parseInt(login_user_id);
			listUsc = ucs.getAllUserComents(target_user_id,userId);
			cr.setCode(200);
			cr.setMessage("success");
		} catch (Exception e) {
			int target_user_id = 0 ;
			int userId = 0;
			cr.setCode(404);
			cr.setMessage("file");
		}

		cr.setData(listUsc);
//		for (int i = 0; i < listUsc.size(); i++) {
//			System.out.println(listUsc.get(i));
//		}
		response.setContentType("application/json;charset=utf-8");
		System.out.println(cr.toJsonString());
		response.getWriter().write(cr.toJsonString());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
}
